<?php

/**
 * This is the model class for table "users".
 *
 * The followings are the available columns in table 'users':
 * @property string $user_id
 * @property integer $user_group_id
 * @property string $user_name
 * @property string $password
 * @property string $email
 * @property string $oauth_uid
 * @property string $oauth_provider
 * @property string $birthday
 * @property integer $gender
 * @property string $avatar
 * @property string $mobile
 * @property integer $mob_setting
 * @property string $phone
 * @property integer $im_hide
 * @property string $last_ip_address
 * @property string $salt
 * @property integer $status
 * @property string $user_activation_key
 * @property string $email_activation_key
 * @property string $time_joined
 * @property string $last_login
 * @property string $last_activity
 */
class Users extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'users';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_group_id, oauth_uid, oauth_provider, status, email_activation_key, time_joined', 'required'),
			array('user_group_id, gender, mob_setting, im_hide, status', 'numerical', 'integerOnly'=>true),
			array('user_name', 'length', 'max'=>100),
			array('password', 'length', 'max'=>32),
			array('email, user_activation_key, email_activation_key', 'length', 'max'=>255),
			array('oauth_uid, oauth_provider', 'length', 'max'=>200),
			array('birthday, salt, time_joined, last_login, last_activity', 'length', 'max'=>10),
			array('avatar', 'length', 'max'=>75),
			array('mobile, phone, last_ip_address', 'length', 'max'=>15),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('user_id, user_group_id, user_name, password, email, oauth_uid, oauth_provider, birthday, gender, avatar, mobile, mob_setting, phone, im_hide, last_ip_address, salt, status, user_activation_key, email_activation_key, time_joined, last_login, last_activity', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' => 'User',
			'user_group_id' => 'User Group',
			'user_name' => 'User Name',
			'password' => 'Password',
			'email' => 'Email',
			'oauth_uid' => 'Oauth Uid',
			'oauth_provider' => 'Oauth Provider',
			'birthday' => 'Birthday',
			'gender' => 'Gender',
			'avatar' => 'Avatar',
			'mobile' => 'Mobile',
			'mob_setting' => 'Mob Setting',
			'phone' => 'Phone',
			'im_hide' => 'Im Hide',
			'last_ip_address' => 'Last Ip Address',
			'salt' => 'Salt',
			'status' => 'Status',
			'user_activation_key' => 'User Activation Key',
			'email_activation_key' => 'Email Activation Key',
			'time_joined' => 'Time Joined',
			'last_login' => 'Last Login',
			'last_activity' => 'Last Activity',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id,true);
		$criteria->compare('user_group_id',$this->user_group_id);
		$criteria->compare('user_name',$this->user_name,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('oauth_uid',$this->oauth_uid,true);
		$criteria->compare('oauth_provider',$this->oauth_provider,true);
		$criteria->compare('birthday',$this->birthday,true);
		$criteria->compare('gender',$this->gender);
		$criteria->compare('avatar',$this->avatar,true);
		$criteria->compare('mobile',$this->mobile,true);
		$criteria->compare('mob_setting',$this->mob_setting);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('im_hide',$this->im_hide);
		$criteria->compare('last_ip_address',$this->last_ip_address,true);
		$criteria->compare('salt',$this->salt,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('user_activation_key',$this->user_activation_key,true);
		$criteria->compare('email_activation_key',$this->email_activation_key,true);
		$criteria->compare('time_joined',$this->time_joined,true);
		$criteria->compare('last_login',$this->last_login,true);
		$criteria->compare('last_activity',$this->last_activity,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Users the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
